<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    body{
        margin: 0;
        padding: 0;
    }
</style>
<body>
    <canvas width="500" height="500px">
     
    </canvas>

    <script>
        let canvas = document.querySelector("canvas")
        let ctx = canvas.getContext("2d")
        canvas.onmousedown = function (event) {
            let mouseX = event.clientX
            let mouseY = event.clientY
            ctx.moveTo(mouseX, mouseY)
            canvas.onmousemove = function (e) {
                let mouseX = e.clientX
                let mouseY = e.clientY
                ctx.lineTo(mouseX,mouseY)
                ctx.stroke()
            }
            canvas.onmouseup=function(){
              canvas.onmousemove=null
                
            }
        }

    </script>
</body>

</html>